package service;

import dao.GoodsDao;
import dao.UserDao;
import model.Goods;

import java.sql.SQLException;
import java.util.List;

public class GoodsService {
    private GoodsDao gDao = new GoodsDao();

    // 添加获取所有商品的方法
    public List<Goods> getGoodsList() {
        return gDao.getGoodsList();
    }

    public Goods getGoodsById(int id) {
        try {
            return gDao.getGoodsById(id);
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }
    public boolean delete(int id){
        try{
            gDao.delete(id);
            return true;
        }catch (SQLException e){
            e.printStackTrace();
            return false;
        }
    }
    public void insert(Goods goods){
        try {
            gDao.insert(goods);
        }catch(SQLException e) {
            e.printStackTrace();
        }
    }
    public Goods getUserById(int id) {
        Goods goods = null;
        try {
            goods = gDao.getUserById(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return goods;
    }
    public void updateUser(Goods goods) {
        try {
            gDao.updateGoodsAddress(goods);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
